"""
@Project ：Python 
@File    ：08-函数综合案例.py
@IDE     ：PyCharm 
@Author  ：DongCha
@Date    ：2023/11/7 0007 18:53 
"""
import time

# 全局变量
# 余额
money = 5000
# 用户名
username = None


def menu(user):
    """
    打印菜单
    :param user: 用户名
    :return: None
    """
    print("-" * 10 + "主菜单" + "-" * 10)
    print(f"{user}，您好，欢迎来到银行，请选择您的操作：")
    print("1. 查询余额")
    print("2. 存款")
    print("3. 取款")
    print("4. 退出")
    return input("请选择：")


def yve(show_header):
    """
    查询余额
    :param show_header: 是否显示头部信息
    :return: None
    """
    global select
    if show_header:
        print("-" * 10 + "查询余额" + "-" * 10)
    print(f"{username}，您好，您的余额剩余：{money}元")
    if show_header:
        print("三秒后返回主菜单")
        time.sleep(3)


def qvkuan(num):
    """
    取款
    :param num: 取多少
    :return: None
    """
    global money, select
    money -= int(num)
    print("-" * 10 + "取款" + "-" * 10)
    print(f"{username}取款{num}元成功")
    yve(False)
    print("三秒后返回主菜单")
    time.sleep(3)


def cunkuan(num):
    """
    存款
    :param num: 存多少
    :return: None
    """
    global money, select
    money += int(num)
    print("-" * 10 + "存款" + "-" * 10)
    print(f"{username}存款{num}元成功")
    yve(False)
    print("三秒后返回主菜单")
    time.sleep(3)


def err():
    """
    菜单选项输入错误
    :return: None
    """
    print("请输入正确的选项，三秒后返回主菜单")
    time.sleep(3)


if __name__ == '__main__':
    while True:
        username = input("您好，请您输入您的姓名：")
        select = menu(username)
        while username:
            if select == "1":
                yve(True)
                select = menu(username)
                continue
            elif select == "2":
                cunkuan(input("请输入存款金额："))
                select = menu(username)
                continue
            elif select == "3":
                qvkuan(input("请输入存款金额："))
                select = menu(username)
                continue
            elif select == "4":
                username = None
                continue
            else:
                err()
                select = menu(username)
                continue
